import mongoose, { Document, Schema } from 'mongoose';

// 项目接口定义
export interface IProject extends Document {
  name: string;
  description: string;
  status: string;
  startDate: Date;
  endDate?: Date;
  members: string[];
  createdBy: string;
  createdAt: Date;
  updatedAt: Date;
}

// 项目状态枚举
export enum ProjectStatus {
  PLANNING = '规划中',
  IN_PROGRESS = '进行中',
  COMPLETED = '已完成',
  ON_HOLD = '已暂停',
  CANCELLED = '已取消'
}

// 项目Schema定义
const ProjectSchema: Schema = new Schema(
  {
    name: {
      type: String,
      required: [true, '项目名称不能为空'],
      trim: true,
      maxlength: [100, '项目名称不能超过100个字符']
    },
    description: {
      type: String,
      required: [true, '项目描述不能为空'],
      trim: true
    },
    status: {
      type: String,
      required: true,
      enum: Object.values(ProjectStatus),
      default: ProjectStatus.PLANNING
    },
    startDate: {
      type: Date,
      required: [true, '项目开始日期不能为空'],
      default: Date.now
    },
    endDate: {
      type: Date
    },
    members: [{
      type: String,
      required: true
    }],
    createdBy: {
      type: String,
      required: [true, '创建者不能为空']
    }
  },
  {
    timestamps: true
  }
);

// 创建并导出模型
export default mongoose.model<IProject>('Project', ProjectSchema); 